package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.entity.Briefing;
import com.hbnu.system.service.IBriefingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/brifing")
@Api(tags = "科研简报模块")
public class BriefingController {
    @Autowired
    IBriefingService iBriefingService;

    @ApiOperation("科研简报-录入")
    @PostMapping("/addBriefing")
    public Rest<Boolean> addBriefing(@RequestBody Briefing briefing){
        boolean add = iBriefingService.addBriefing(briefing);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研简报-删除")
    @GetMapping("/DeleteBriefing")
    public Rest<Boolean> DeleteBriefing(String briefingID){
        boolean delete = iBriefingService.deleteBriefing(briefingID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研简报-修改")
    @PostMapping("/updateBriefing")
    public Rest<Boolean> updateBriefing(@RequestBody Briefing briefing){
        boolean update = iBriefingService.updateBriefing(briefing);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键科研简报查询")
    @GetMapping("/GetBriefingById")
    public Rest<Briefing> GetBriefingById(String briefingID){
        Briefing briefing = iBriefingService.getBriefing(briefingID);
        return Rest.success(briefing);
    }

    @ApiOperation("科研简报-分页查询")
    @PostMapping ("/pageBriefingCondition")
    public Rest<CommonPage<Briefing>> pageBriefingCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Briefing> page = iBriefingService.pageCondition(searchTaskDTO);
        CommonPage<Briefing> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }

}

